package com.example.april2.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ExamController {

    @RequestMapping("/")
    public String index(HttpServletRequest request, Model model) {
        String name = (String) request.getSession().getAttribute("name");
        if (name != null){
            model.addAttribute("name",name);
            return "success";
        }else {
            return "login";
        }
    }

    @RequestMapping("/logout")
    public String logout(HttpServletRequest request, Model model) {
        request.getSession().setAttribute("id",null);
        request.getSession().setAttribute("name",null);
        return "redirect:/";
    }
}
